package com.exercises;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//缺失的第一个正数
class Exercise90 {
    public static void main(String[] args) {
        int[] abc = new int[]{1, 1};
        System.out.println(JSONObject.toJSONString(subsetsWithDup(abc)));
    }


    List<Integer> t = new ArrayList<Integer>();
    List<List<Integer>> result = new ArrayList<List<Integer>>();


    public static List<List<Integer>> subsetsWithDup(int[] nums) {
        List result = new ArrayList();
        if (nums.length == 0) {
            result.add(new ArrayList<>());
            return result;
        }
        Arrays.sort(nums);
        int length = nums.length;
        int value = nums[length - 1];
        int[] child = Arrays.copyOf(nums, length - 1);

        List<List<Integer>> before = subsetsWithDup(child);

        boolean duplicate = false;
        if (length >= 2 && nums[length - 1] == nums[length - 2]) {
            duplicate = true;
        }

        for (List<Integer> item : before) {
            result.add(item);


            if (duplicate && !item.contains(value)) {
                continue;
            } else {
                List<Integer> list = new ArrayList<>(item);
                list.add(value);
                result.add(list);
            }
        }

        return result;
    }


    public static void dfs(boolean preChoose, int index, int[] nums) {

    }

}
